<template>
	<view>
		<u-search v-model="keyword" :show-action="false" @change="search" placeholder="请输入关键字"></u-search>
		<u-list @scrolltolower="scrolltolower" v-if='list.length!==0 || status=="loading"'>
			<u-list-item v-for="(item, index) in list" :key="index">
				<u-cell :title="(index+1)+'、'+ item.FullName" isLink :name="item.Id"
					icon="https://cdn.uviewui.com/uview/example/tag.png"
					:label="`${item.Addr || ''} 光功率:${item.Opticalpower} 端口:${item.Fdn} 物理地址:${item.Mac}`" @click="openpage">
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" />
		</u-list>
		<u-empty v-if='list.length==0 && status!="loading"' mode="list" icon="https://project.gxrunxiang.com/cdn/list.png">
		</u-empty>
	</view>
</template>

<script>
	import {
		GetProtOpticalPowerList
	} from '@/common/api.js'
	export default {
		data() {
			return {
				list: [],
				keyword: "",
				pageIndex: 1, //当前页数
				pageSize: 20, //页数大小
				totalPage: "", //总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				loading: true,
				user: JSON.parse(uni.getStorageSync("$userinfo")),
			}
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			openpage(e) {
				uni.navigateTo({
					url: "powerdetail?id=" + e.name
				})
			},
			scrolltolower() {
				if (this.status != "nomore")
					this.pageIndex++
				this.getlist()
			},
			search()
			{
				this.pageIndex=1
				this.list=[]
				this.getlist()
			},
			getlist() {
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters: [],
					jsonPara:"[]"
				}
				if (this.keyword != "") {
					// para.Parameters.push({
					// 	FieldName: "cmtsname",
					// 	ConditionalType: "Like",
					// 	FieldValue: this.keyword
					// })
					var userfilter = {
						"ConditionalList": [{
							"Key": 0,
							"Value": {
								"FieldName": "Addr",
								"FieldValue": this.keyword,
								"ConditionalType": "Like"
							}
						}, {
							"Key": 1,
							"Value": {
								"FieldName": "Fdn",
								"FieldValue": this.keyword,
								"ConditionalType": "Like"
							}
						}, {
							"Key": 1,
							"Value": {
								"FieldName": "Mac",
								"FieldValue": this.keyword,
								"ConditionalType": "Like"
							}
						}]
					}
					para.jsonPara = JSON.stringify([userfilter])
				}
				para.OrderBys = ['Opticalpower asc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex


				this.status = "loading"
				GetProtOpticalPowerList(para).then(res => {
					if (this.pageIndex * this.pageSize >= res.count)
						this.status = "nomore"
					else
						this.status = "loadmore"
					this.list.push(...res.data)
				})
			}
		},
	}
</script>

<style>
	.rightButton{
		float: right;
	}
</style>